package com.zm.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zm.bean.TestUserBean;
import com.zm.dao.TestUserBeanMapper;


//@RestController等价于@Controller和@ResponseBody
@RestController
public class Restcontroller {
	@Resource
	private TestUserBeanMapper test;
	
	
	@RequestMapping("queryPathVariable2/{userid}")
	public  List<TestUserBean> queryPathVariable(@PathVariable("userid")Integer userid){
		//查询数据为userid={userid}的数据
		List<TestUserBean> listPath=test.queryByUserid(userid);
		return listPath; 
	}
	/**
	 * 查询所有成员数据
	 * 使用GET请求方式
	 * 使用ResponseEntity返回json数据
	 * @return
	 */
	@RequestMapping(value="/queryRestEntity/",method=RequestMethod.GET)
	public ResponseEntity<List<TestUserBean>>queryResponseEntity(){
		List<TestUserBean> list=test.queryUserInfoAll();
		//第一种ResponseEntity返回json方式，静态方法返回
		return ResponseEntity.status(HttpStatus.OK).body(list);
	}
	/**
	 * 查询单个成员
	 * 使用GET请求方式
	 * 使用ResponseEntity返回json数据
	 * @return
	 */
	@RequestMapping(value="/queryRestEntity/{userid}",method=RequestMethod.GET)
	public ResponseEntity<List<TestUserBean>>queryResponseEntity(@PathVariable("userid")Integer userid){
		List<TestUserBean> list=test.queryByUserid(userid);
		//第二种ResponseEntity返回json方式，匿名对象返回，使用构造参数返回
		return new  ResponseEntity<List<TestUserBean>>(list,HttpStatus.OK);
	}
	
}
